package com.test.jdk8.demo2;

/**
 * @ClassName Lambda4
 * @Description TODO
 * @Author 维康
 * @Date 2018/7/10 10:40
 * @Version 1.0
 **/
public class Lambda4 {

    /**
     * 访问对象字段与静态变量
     */
    static int outerStaticNum;
    int outerNum;
    void testScopes() {

        final String out = "访问局部变量只能是final";

        Converter<Integer, String> stringConverter1 = (from) -> {
            outerNum = 23;
            System.out.println(out);
            return String.valueOf(from);
        };
        Converter<Integer, String> stringConverter2 = (from) -> {
            outerStaticNum = 72;
            return String.valueOf(from);
        };
    }

    public static void main(String[] args){

        Converter<String, Integer> converter = (from) -> Integer.valueOf(from);
        Integer converted = converter.convert("123");
        // 123
        System.out.println(converted);

    }
}
/**
 * 函数式接口
 * @param <F>
 * @param <T>
 */
@FunctionalInterface
interface Converter<F, T> {
    T convert(F from);
}
